<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加网址</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="css/weuix.min.css"/>
    <script src="js/zepto.min.js"></script>
</head>
<body ontouchstart style="background-color: #f8f8f8;">
<div class="weui_cells_title">待检测网址</div>
<div class="weui_cells weui_cells_form">
    <div class="weui_cell">
        <div class="weui_cell_hd"><label class="weui_label">名称</label></div>
        <div class="weui_cell_bd weui_cell_primary">
            <input id="name-input" class="weui_input" placeholder="请输入网址名称" />
        </div>
    </div>

    <div class="weui_cell">
        <div class="weui_cell_hd"><label class="weui_label">网址</label></div>
        <div class="weui_cell_bd weui_cell_primary">
            <input id="url-input" class="weui_input" placeholder="请输入完整路径，包含http://或者https://" />
        </div>
    </div>
</div>
<div class="weui_btn_area">
    <a id="formSubmitBtn" href="javascript:submit_f()" class="weui_btn weui_btn_primary">提交</a>
</div>

<script src="js/vconsole.min.js"></script>
<script src="js/common-20180604.js"></script>
<script>
    // new VConsole();

    checkUserid();

    function submit_f(){
        if ($("#url-input").val()){
            $.ajax({
                url: "/url",
                type: "post",
                contentType : 'application/json;charset=UTF-8',
                data: JSON.stringify({
                    name: $("#name-input").val(),
                    url: $("#url-input").val(),
                    userid: localStorage.getItem("userid")
                }),
                success: function (data) {
                    console.log(data);
                    if (data == "ok") {
                        $.toast("添加成功");
                    } else {
                        $.toast("添加失败");
                    }
                }
            });
        } else {
            $.toast("请输入网站名称", 1000);
        }
    }

</script>
</body>
</html>